/*
Paper title: "Impact of Juntos conditional cash transfer program on nutritional and cognitive outcomes in Peru: ///
Comparison between younger and older initial exposure"
Authors: Alan Sánchez, Guido Melendez, Jere Behrman
Code written by: Alan Sánchez & Guido Melendez
Note: this analysis uses datafile "index_sibR1R4", which contains merged data from different rounds of the Young Lives Study in Peru.
*/

clear all
set matsize 5000
set memory 4000m
set maxvar 20000
set more off

* insert directory here
loc ruta   "F:\JUNTOS\_1 files"
loc rutaf  "F:\JUNTOS\_2 results"
loc rutagr "F:\JUNTOS\_3 graphics"

***********************************************************************************
* Appendix A																	  *	
*							Table A.1											  *	
***********************************************************************************

/* This do file replicates table A.1 of the Appendix A */

cd "`ruta'"

use index_sibR1R4, clear
sort CHILDID

*** Only children with siblings
duplicates tag CHILDID,generate(duplicate)
tab duplicate
gen twosibling=1
replace twosibling=0 if duplicate==0
drop duplicate

drop if CHILDID=="PE201100" & ID==16
drop if CHILDID=="PE171035" & ID==5
drop if CHILDID=="PE031085" & ID==17
drop if CHILDID=="PE091051" & ID==18
drop if CHILDID=="PE161080" & ID==4
drop if CHILDID=="PE201100"	& ID==16
drop if CHILDID=="PE091078"	& ID==6

* Create dummies by households
sort CHILDID
egen hh=group(CHILDID)

* Create age in years 
gen age_45=int(age_months_45/12)
replace age_45=4 if age_45==3
replace age_45=6 if age_45==7

gen age_78=int(age_months_78/12)
replace age_78=7 if age_78==5
replace age_78=10 if age_78==11

* Standardizing PPVT scores
egen std1=std(PPVT_45) if age_months_45>=37 & age_months_45<42
egen std2=std(PPVT_45) if age_months_45>=43 & age_months_45<48
egen std3=std(PPVT_45) if age_months_45>=49 & age_months_45<54
egen std4=std(PPVT_45) if age_months_45>=55 & age_months_45<60
egen std5=std(PPVT_45) if age_months_45>=61 & age_months_45<66
egen std6=std(PPVT_45) if age_months_45>=67 & age_months_45<72 
gen std_PPVT_45=.
replace std_PPVT_45=std1 if age_months_45>=37 & age_months_45<42
replace std_PPVT_45=std2 if age_months_45>=43 & age_months_45<48
replace std_PPVT_45=std3 if age_months_45>=49 & age_months_45<54
replace std_PPVT_45=std4 if age_months_45>=55 & age_months_45<60
replace std_PPVT_45=std5 if age_months_45>=61 & age_months_45<66
replace std_PPVT_45=std6 if age_months_45>=67 & age_months_45<72 
label var std_PPVT_45 "Standardized PPVT raw original score, 4-5 age"
drop std1 std2 std3 std4 std5 std6

egen std7=std(PPVT_78)  if age_months_78>=73  & age_months_78<78
egen std8=std(PPVT_78)  if age_months_78>=79  & age_months_78<84
egen std9=std(PPVT_78)  if age_months_78>=85  & age_months_78<90
egen std10=std(PPVT_78) if age_months_78>=91  & age_months_78<96
egen std11=std(PPVT_78) if age_months_78>=97  & age_months_78<102
egen std12=std(PPVT_78) if age_months_78>=103 & age_months_78<108
egen std13=std(PPVT_78) if age_months_78>=109 & age_months_78<114
egen std14=std(PPVT_78) if age_months_78>=115 & age_months_78<120 

gen std_PPVT_78=.
replace std_PPVT_78=std7  if age_months_78>=73  & age_months_78<78
replace std_PPVT_78=std8  if age_months_78>=79  & age_months_78<84
replace std_PPVT_78=std9  if age_months_78>=85  & age_months_78<90
replace std_PPVT_78=std10 if age_months_78>=91  & age_months_78<96
replace std_PPVT_78=std11 if age_months_78>=97  & age_months_78<102
replace std_PPVT_78=std12 if age_months_78>=103 & age_months_78<108
replace std_PPVT_78=std13 if age_months_78>=109 & age_months_78<114
replace std_PPVT_78=std14 if age_months_78>=115 & age_months_78<120 
label var std_PPVT_78 "Standardized PPVT raw original score, 7-8 age"
drop std7 std8 std9 std10 std11 std12 std13 std14 

* Extreme stunting
gen estunted_45=0
replace estunted_45=1 if zhfa_45<-3
replace estunted_45=. if zhfa_45==.
label var estunted_45 "Child is extremely stunted, 4-5 age"

gen estunted_78=0
replace estunted_78=1 if zhfa_78<-3 
replace estunted_78=. if zhfa_78==.
label var estunted_78 "Child is extremely stunted, 7-8 age"

* Rule of elegibility, round 2

clonevar tipom2R2=tipom2_45 if sib==0
clonevar tipom3R2=tipom3_45 if sib==0
clonevar tipom4R2=tipom4_45 if sib==0
clonevar serv3R2=serv3_45 if sib==0
clonevar n_equipR2=n_equip_45 if sib==0
clonevar combustR2=combust_45 if sib==0
clonevar women_weducR2=women_weduc_45 if sib==0
clonevar edu_men614R2=edu_men614_45 if sib==0
clonevar edu_men617R2=edu_men617_45 if sib==0
clonevar age_caregiverR2=age_caregiver_45 if sib==0
clonevar HHSIZER2=HHSIZE_45 if sib==0

foreach x in altitudeR2 tipom2R2 tipom3R2 tipom4R2 serv3R2 n_equipR2 combustR2 women_weducR2 edu_men614R2 edu_men617R2 age_caregiverR2 HHSIZER2 hh_agricR2 hh_noactR2 {
replace `x'=0 if `x'==.
bys CHILDID: egen junk`x'=sum(`x')
replace `x'=junk`x'
drop junk`x'
}

* Diferences in HAZ, sibling

foreach y in std_PPVT zhfa estunted stunted {
gen dif`y'=`y'_78-`y'_45 
} 

label var difstd_PPVT "Change in standardized ppvt score"
label var difzhfa "Change in haz"
label var difstunted "Change in stunting"
label var difstunted "Change in stunting"

order CHILDID ID sib ybirth mbirth monthdob METH MUMED CAREED CETH mum_analf care_analf CLUSTIDR1 zhfaR1 ///
altitudeR1 tipom2R1 tipom3R1 tipom4R1 serv3R1 n_equipR1 ///
combustR1 women_weducR1 edu_men614R1 edu_men617R1 HHSIZER1 age_caregiverR1 hh_agricR1 hh_noactR1 ///
altitudeR2 tipom2R2 tipom3R2 tipom4R2 serv3R2 n_equipR2 ///
combustR2 women_weducR2 edu_men614R2 edu_men617R2 HHSIZER2 age_caregiverR2 hh_agricR2 hh_noactR2 female CLANG

************************************************
*                PANEL DATA                    *
************************************************

reshape long date_int_ year_ rural_ electricity_ water_ drain_ serv3_ floor_ roof_ wall_ combust_ n_equip_ hq_ ///
cd_ sv_ wi_ tipom1_ tipom2_ tipom3_ tipom4_ totalexp_rpc_ HHSIZE_ edu_men614_ edu_men617_ women_weduc_ ///
age_mother_ age_caregiver_ age_months_ zhfa_ stunted_ PPVT_ age_ std_PPVT_ estunted_ ATTNDSCHL_ GRADE_ ppvtlang_ ///
, i(CHILDID ID sib) j(round)

foreach x in date_int year rural electricity water drain serv3 floor roof wall combust n_equip hq ///
cd sv wi tipom1 tipom2 tipom3 tipom4 totalexp_rpc HHSIZE edu_men614 edu_men617 women_weduc ///
age_mother age_caregiver age_months zhfa stunted PPVT age std_PPVT estunted ATTNDSCHL GRADE ppvtlang ///
{
rename `x'_ `x'
}
 
label var date_int "Date of interview (in months)"
label var year "Year of interview"
label var rural "Area of residence is rural"
label var electricity "Dwelling has electricity"
label var water "Main source of drinking water is Piped into dwelling/yard/plot"
label var drain "Type of toilet facility is Flush toilet/septic tank in dwelling"
label var serv3 "Number of basic public services" 
label var floor "Main floor material is high quality material" 
label var roof "Main roof material is high quality material"
label var wall "Main wall material is high quality material"
label var combust "Main fuel for cooking is gas, electricity or kerosene"
label var n_equip "Number of assets household doesn't have"
label var hq "Housing queality index"
label var cd "Consumer durables index"
label var sv "Access to services index"
label var wi "Wealth index"
label var tipom1 "Type of housing quality: very low"
label var tipom2 "Type of housing quality: low"
label var tipom3 "Type of housing quality: medium"
label var tipom4 "Type of housing quality: high"
label var totalexp_rpc "Total real consumption per capita - base 2006"
label var HHSIZE "Household size"
label var edu_men614 "Percentage of children who are in full-time education (6-17)"
label var edu_men617 "Percentage of children who are in full-time education (6-14)"
label var women_weduc "Percentage of adult women without formal education"
label var age_mother "Age of mother (in years)"
label var age_caregiver "Age of mother (in years)" 
label var age_months "Age of child in months"
label var zhfa "Heigh-for-age z score"
label var stunted "Child is stunted"
label var PPVT "PPVT original raw score"
label var age "Age of child (in years)"
label var std_PPVT "Standardized PPVT original raw score"
label var estunted "Child is extremely stunted"
label var ATTNDSCHL "Are you currenty in full-time education?"
label var GRADE "Highest grade attainment or current school grade"
label var ppvtlang "Language used by child during PPVT test"

replace round=0 if round==45
replace round=1 if round==78
label define round 0 "Before" 1 "After"
label values round round
format %10.0g round
label var round "After treatment"

* Defining as a paned

sort CHILDID sib
egen pid=group(CHILDID sib)

*xtset pid round

* Families enrolled to JUNTOS in 2005 and 2006 (not to be considered)
gen baselinejuntos=1
replace baselinejuntos=0 if yenrolljuntos==2005 | yenrolljuntos==2006

* Siblings exposed at 4 or 5 age during JUNTOS' first expansion (not to be considered)
gen years03=1
replace years03=0 if sib==1 & age_enrollment==4 
replace years03=0 if sib==1 & age_enrollment==5

* Age in semesters
gen semester4=(age_months<=24) & round==0
gen semester5=(age_months>24 & age_months<=30) & round==0
gen semester6=(age_months>30 & age_months<=36) & round==0
gen semester7=(age_months>36 & age_months<=42) & round==0
gen semester8=(age_months>42 & age_months<=48) & round==0
gen semester9=(age_months>48 & age_months<=54) & round==0
gen semester10=(age_months>54 & age_months<=60) & round==0
gen semester11=(age_months>60 & age_months<=66) & round==0
gen semester12=(age_months>66 & age_months<=72) & round==0
gen semester13=(age_months>72 & age_months<=78) & round==0
gen semester14=(age_months>78 & age_months<=92) & round==0

* Groups of Juntos' families
gen juntosgroup=. 
replace juntosgroup=1 if juntosuntilR3==1 | juntosuntilR3==2
replace juntosgroup=2 if juntosuntilR3==0 & (juntosuntilR4==1 | juntosuntilR4==2)
replace juntosgroup=3 if juntosuntilR3==0 & juntosuntilR4==0
label var juntosgroup "Type of Juntos's treatment R2-R3" 
label define juntosgroup 1 "Treated R2-R3" 2 "Treated R3-R4" 3 "Never treated" 
label values juntosgroup juntosgroup 

* Create a dummy equal 1 if child recieves Juntos in R2-R3 and is observed after treatment
gen aftjuntosR3=rec_juntos*round
label var aftjuntosR3 "Child receives Juntos in R3, observed after treatment"

* Family recieves Juntos in R3-R4
gen juntosr4=.
replace juntosr4=0 if juntosuntilR4==0 & juntosuntilR3==0  
replace juntosr4=1 if juntosuntilR3==0 & (juntosuntilR4==1 | juntosuntilR4==2)
label var juntosr4 "Family recieves Juntos in R4"

* Create a dummy equal 1 if child recieves Juntos in R3-R4 and is observed after treatment
gen aftjuntosR4=juntosr4*round
label var aftjuntosR4 "Child receives Juntos in R4, observed after treatment"

label var zhfaR1 "Index' height-for-age z score, round 1"

***********************************************************************
*																	  *	
*                          ESTIMATIONS                                *	
*																	  *	
***********************************************************************

* Defining globals

global household "MUMED CETH wiR1"
global child "female i.age"
global child2 "female i.age i.ppvtlang"
global district "prom_nbi"
global cluster "CHILDID"
global clusterid "ubigeoR1"
global condition "(quintil==1 | quintil==2) & altitudeR2>500"
global sample_j1 "sample==1"
global sample_j2 "cogsample==1"
global datejuntos "baselinejuntos==1"
global criticalperiod "years03==1"
global cogcontrol "i.ppvtlang"
global treatmentr3 "rec_juntos round aftjuntosR3"
global fetreatmentr3 "round aftjuntosR3"
global treatmentr4 "juntosr4 round aftjuntosR4"
global fetreatmentr4 "round aftjuntosR4"

* Defining sample for nutrition
keep if $criticalperiod 
xi: areg zhfa $household $child $district if $condition & $datejuntos, abs($cluster)
gen junksample=e(sample)

duplicates tag CHILDID if junksample==1, gen(rep)
gen sample=0
replace sample=1 if rep==3
drop junksample rep

* Creating adtional variables

gen q1q2twosib=.
replace q1q2twosib=1 if $sample_j1 
replace q1q2twosib=0 if sample==0 & twosibling==1

gen q1q2vsrest=.
replace q1q2vsrest=1 if $sample_j1 
replace q1q2vsrest=0 if sample==0 & twosibling==0

gen secondjuntos=0
replace secondjuntos=1 if rec_juntos==0 & (juntosuntilR4==1 | juntosuntilR4==2)

* Groups of Juntos' families

gen group1vs2=.
replace group1vs2=1 if juntosgroup==1
replace group1vs2=0 if juntosgroup==2

gen group1vs3=.
replace group1vs3=1 if juntosgroup==1
replace group1vs3=0 if juntosgroup==3

gen group2vs3=.
replace group2vs3=1 if juntosgroup==2
replace group2vs3=0 if juntosgroup==3

* afirmation: Among household that are Juntos beneficiaries, the large majority has more than one child. It is true?

duplicates tag CHILDID, gen(rep)

gen twochildren=rep!=1
label var twochildren "Household has more than one child"
label define twochildren 0 "No" 1 "Yes"
label values twochildren twochildren 

gen afil_juntos=(rec_juntos==1 | juntosr4==1)
label var afil_juntos "Household is enrolled to JUNTOS"
label define afil_juntos 0 "No" 1 "Yes"
label values afil_juntos afil_juntos 

tab twochildren afil_juntos, col

******************************************************************
******************************************************************
************************  TABLE A.1  *****************************
******************************************************************
******************************************************************

matrix TABLE1=J(41,9,.)

matrix colnames TABLE1= "Rest YL households" "2 sibling households" "2 sibling households (Q1 Y Q2)" "(2)-(1)" "p value" "(3)-(2)" "p value" "(3)-(1)" "p-value" 
matrix rownames TABLE1= "Index" "haz 1 to 2 R1" "haz 4 to 5 R2" "haz 7 to 8 R3" "PPVT 4 to 5 R2" "PPVT 7 to 8 R3" "Esteem 7 to 8 R3" "Efficacy 7 to 8 R3" "Female" ///
"Sibling" "haz 4 to 5 R3" "haz 7 to 8 R4" "PPVT 4 to 5 R3" "PPVT 7 to 8 R4" "Esteem 7 to 8 R4" "Efficacy 7 to 8 R4" "Female" ///
"Household" "Hq R1" "basic public sv R1" "assets does not have R1" "fuel of cooking R1" "women no education R1" "Children full time educ R1" "Juntos 2005 to 2007" "Juntos 2010 +" ///
"Altitude R1" "Rural R1" "HH size R1" "wi R1" "Consumption R2" "Not spanish" "Age caregiver R1" "Years education" "Agriculture R1" "District" "poverty" "severe poverty" "Chronic malnutrition" "NBIS" "Politic violence"

sum zhfaR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[2,1]=r(mean)
sum zhfaR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[2,2]=r(mean)
sum zhfaR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[2,3]=r(mean)
matrix TABLE1[2,4]=TABLE1[2,2]-TABLE1[2,1]
ttest zhfaR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[2,5]=r(p)
ttest zhfaR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[2,6]=TABLE1[2,3]-TABLE1[2,2]
matrix TABLE1[2,7]=r(p)
ttest zhfaR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[2,8]=TABLE1[2,3]-TABLE1[2,1]
matrix TABLE1[2,9]=r(p)

sum zhfa if sib==0 & round==0 & twosibling==0
matrix TABLE1[3,1]=r(mean)
sum zhfa if sib==0 & round==0 & twosibling==1
matrix TABLE1[3,2]=r(mean)
sum zhfa if sib==0 & round==0 & $sample_j1
matrix TABLE1[3,3]=r(mean)
matrix TABLE1[3,4]=TABLE1[3,2]-TABLE1[3,1]
ttest zhfa if sib==0 & round==0 , by(twosibling)
matrix TABLE1[3,5]=r(p)
ttest zhfa if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[3,6]=TABLE1[3,3]-TABLE1[3,2]
matrix TABLE1[3,7]=r(p)
ttest zhfa if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[3,8]=TABLE1[3,3]-TABLE1[3,1]
matrix TABLE1[3,9]=r(p)

sum zhfa if sib==0 & round==1 & twosibling==0
matrix TABLE1[4,1]=r(mean)
sum zhfa if sib==0 & round==1 & twosibling==1
matrix TABLE1[4,2]=r(mean)
sum zhfa if sib==0 & round==1 & $sample_j1
matrix TABLE1[4,3]=r(mean)
matrix TABLE1[4,4]=TABLE1[4,2]-TABLE1[4,1]
ttest zhfa if sib==0 & round==1 , by(twosibling)
matrix TABLE1[4,5]=r(p)
ttest zhfa if sib==0 & round==1 , by(q1q2twosib)
matrix TABLE1[4,6]=TABLE1[4,3]-TABLE1[4,2]
matrix TABLE1[4,7]=r(p)
ttest zhfa if sib==0 & round==1, by(q1q2vsrest)
matrix TABLE1[4,8]=TABLE1[4,3]-TABLE1[4,1]
matrix TABLE1[4,9]=r(p)

*global PPVT "std_PPVT" 
global PPVT "PPVT"

sum $PPVT if sib==0 & round==0 & twosibling==0
matrix TABLE1[5,1]=r(mean)
sum $PPVT if sib==0 & round==0 & twosibling==1
matrix TABLE1[5,2]=r(mean)
sum $PPVT if sib==0 & round==0 & $sample_j1
matrix TABLE1[5,3]=r(mean)
matrix TABLE1[5,4]=TABLE1[5,2]-TABLE1[5,1]
ttest $PPVT if sib==0 & round==0 , by(twosibling)
matrix TABLE1[5,5]=r(p)
ttest $PPVT if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[5,6]=TABLE1[5,3]-TABLE1[5,2]
matrix TABLE1[5,7]=r(p)
ttest $PPVT if sib==0 & round==0, by(q1q2vsrest)
matrix TABLE1[5,8]=TABLE1[5,3]-TABLE1[5,1]
matrix TABLE1[5,9]=r(p)

sum $PPVT if sib==0 & round==1 & twosibling==0
matrix TABLE1[6,1]=r(mean)
sum $PPVT if sib==0 & round==1 & twosibling==1
matrix TABLE1[6,2]=r(mean)
sum $PPVT if sib==0 & round==1 & $sample_j1
matrix TABLE1[6,3]=r(mean)
matrix TABLE1[6,4]=TABLE1[6,2]-TABLE1[6,1]
ttest $PPVT if sib==0 & round==1 , by(twosibling)
matrix TABLE1[6,5]=r(p)
ttest $PPVT if sib==0 & round==1 , by(q1q2twosib)
matrix TABLE1[6,6]=TABLE1[6,3]-TABLE1[6,2]
matrix TABLE1[6,7]=r(p)
ttest $PPVT if sib==0 & round==1, by(q1q2vsrest)
matrix TABLE1[6,8]=TABLE1[6,3]-TABLE1[6,1]
matrix TABLE1[6,9]=r(p)

*global esteem "std_esteem"
global esteem "esteem"

sum $esteem if sib==0 & round==1 & twosibling==0
matrix TABLE1[7,1]=r(mean)
sum $esteem if sib==0 & round==1 & twosibling==1
matrix TABLE1[7,2]=r(mean)
sum $esteem if sib==0 & round==1 & $sample_j1
matrix TABLE1[7,3]=r(mean)
matrix TABLE1[7,4]=TABLE1[7,2]-TABLE1[7,1]
ttest $esteem if sib==0 & round==1 , by(twosibling)
matrix TABLE1[7,5]=r(p)
ttest $esteem if sib==0 & round==1 , by(q1q2twosib)
matrix TABLE1[7,6]=TABLE1[7,3]-TABLE1[7,2]
matrix TABLE1[7,7]=r(p)
ttest $esteem if sib==0 & round==1, by(q1q2vsrest)
matrix TABLE1[7,8]=TABLE1[7,3]-TABLE1[7,1]
matrix TABLE1[7,9]=r(p)

*global agency "std_agency"
global agency "agency"

sum $agency if sib==0 & round==1 & twosibling==0
matrix TABLE1[8,1]=r(mean)
sum $agency if sib==0 & round==1 & twosibling==1
matrix TABLE1[8,2]=r(mean)
sum $agency if sib==0 & round==1 & $sample_j1
matrix TABLE1[8,3]=r(mean)
matrix TABLE1[8,4]=TABLE1[8,2]-TABLE1[8,1]
ttest $agency if sib==0 & round==1 , by(twosibling)
matrix TABLE1[8,5]=r(p)
ttest $agency if sib==0 & round==1 , by(q1q2twosib)
matrix TABLE1[8,6]=TABLE1[8,3]-TABLE1[8,2]
matrix TABLE1[8,7]=r(p)
ttest $agency if sib==0 & round==1, by(q1q2vsrest)
matrix TABLE1[8,8]=TABLE1[8,3]-TABLE1[8,1]
matrix TABLE1[8,9]=r(p)

sum female if sib==0 & round==0 & twosibling==0
matrix TABLE1[9,1]=r(mean)
sum female if sib==0 & round==0 & twosibling==1
matrix TABLE1[9,2]=r(mean)
sum female if sib==0 & round==0 & $sample_j1
matrix TABLE1[9,3]=r(mean)
matrix TABLE1[9,4]=TABLE1[9,2]-TABLE1[9,1]
ttest female if sib==0 & round==0 , by(twosibling)
matrix TABLE1[9,5]=r(p)
ttest female if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[9,6]=TABLE1[9,3]-TABLE1[9,2]
matrix TABLE1[9,7]=r(p)
ttest female if sib==0 & round==0, by(q1q2vsrest)
matrix TABLE1[9,8]=TABLE1[9,3]-TABLE1[9,1]
matrix TABLE1[9,9]=r(p)

sum zhfa if sib==1 & round==0 & twosibling==1
matrix TABLE1[11,2]=r(mean)
sum zhfa if sib==1 & round==0 & $sample_j1
matrix TABLE1[11,3]=r(mean)
ttest zhfa if sib==1 & round==0 , by(q1q2twosib)
matrix TABLE1[11,6]=TABLE1[11,3]-TABLE1[11,2]
matrix TABLE1[11,7]=r(p)

sum zhfa if sib==1 & round==1 & twosibling==1
matrix TABLE1[12,2]=r(mean)
sum zhfa if sib==1 & round==1 & $sample_j1
matrix TABLE1[12,3]=r(mean)
ttest zhfa if sib==1 & round==1 , by(q1q2twosib)
matrix TABLE1[12,6]=TABLE1[12,3]-TABLE1[12,2]
matrix TABLE1[12,7]=r(p)

sum $PPVT if sib==1 & round==0 & twosibling==1
matrix TABLE1[13,2]=r(mean)
sum $PPVT if sib==1 & round==0 & $sample_j1
matrix TABLE1[13,3]=r(mean)
ttest $PPVT if sib==1 & round==0 , by(q1q2twosib)
matrix TABLE1[13,6]=TABLE1[13,3]-TABLE1[13,2]
matrix TABLE1[13,7]=r(p)

sum $PPVT if sib==1 & round==1 & twosibling==1
matrix TABLE1[14,2]=r(mean)
sum $PPVT if sib==1 & round==1 & $sample_j1
matrix TABLE1[14,3]=r(mean)
ttest $PPVT if sib==1 & round==1 , by(q1q2twosib)
matrix TABLE1[14,6]=TABLE1[14,3]-TABLE1[14,2]
matrix TABLE1[14,7]=r(p)

sum $esteem if sib==1 & round==1 & twosibling==1
matrix TABLE1[15,2]=r(mean)
sum $esteem if sib==1 & round==1 & $sample_j1
matrix TABLE1[15,3]=r(mean)
ttest $esteem if sib==1 & round==1 , by(q1q2twosib)
matrix TABLE1[15,6]=TABLE1[15,3]-TABLE1[15,2]
matrix TABLE1[15,7]=r(p)

sum $agency if sib==1 & round==1 & twosibling==1
matrix TABLE1[16,2]=r(mean)
sum $agency if sib==1 & round==1 & $sample_j1
matrix TABLE1[16,3]=r(mean)
ttest $agency if sib==1 & round==1 , by(q1q2twosib)
matrix TABLE1[16,6]=TABLE1[16,3]-TABLE1[16,2]
matrix TABLE1[16,7]=r(p)

sum female if sib==1 & round==0 & twosibling==1
matrix TABLE1[17,2]=r(mean)
sum female if sib==1 & round==0 & $sample_j1
matrix TABLE1[17,3]=r(mean)
ttest female if sib==1 & round==0 , by(q1q2twosib)
matrix TABLE1[17,6]=TABLE1[17,3]-TABLE1[17,2]
matrix TABLE1[17,7]=r(p)

sum hqR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[19,1]=r(mean)
sum hqR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[19,2]=r(mean)
sum hqR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[19,3]=r(mean)
matrix TABLE1[19,4]=TABLE1[19,2]-TABLE1[19,1]
ttest hqR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[19,5]=r(p)
ttest hqR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[19,6]=TABLE1[19,3]-TABLE1[19,2]
matrix TABLE1[19,7]=r(p)
ttest hqR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[19,8]=TABLE1[19,3]-TABLE1[19,1]
matrix TABLE1[19,9]=r(p)

sum serv3R1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[20,1]=r(mean)
sum serv3R1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[20,2]=r(mean)
sum serv3R1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[20,3]=r(mean)
matrix TABLE1[20,4]=TABLE1[20,2]-TABLE1[20,1]
ttest serv3R1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[20,5]=r(p)
ttest serv3R1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[20,6]=TABLE1[20,3]-TABLE1[20,2]
matrix TABLE1[20,7]=r(p)
ttest serv3R1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[20,8]=TABLE1[20,3]-TABLE1[20,1]
matrix TABLE1[20,9]=r(p)

sum n_equipR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[21,1]=r(mean)
sum n_equipR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[21,2]=r(mean)
sum n_equipR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[21,3]=r(mean)
matrix TABLE1[21,4]=TABLE1[21,2]-TABLE1[21,1]
ttest n_equipR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[21,5]=r(p)
ttest n_equipR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[21,6]=TABLE1[21,3]-TABLE1[21,2]
matrix TABLE1[21,7]=r(p)
ttest n_equipR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[21,8]=TABLE1[21,3]-TABLE1[21,1]
matrix TABLE1[21,9]=r(p)

sum combustR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[22,1]=r(mean)
sum combustR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[22,2]=r(mean)
sum combustR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[22,3]=r(mean)
matrix TABLE1[22,4]=TABLE1[22,2]-TABLE1[22,1]
ttest combustR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[22,5]=r(p)
ttest combustR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[22,6]=TABLE1[22,3]-TABLE1[22,2]
matrix TABLE1[22,7]=r(p)
ttest combustR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[22,8]=TABLE1[22,3]-TABLE1[22,1]
matrix TABLE1[22,9]=r(p)

sum women_weducR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[23,1]=r(mean)
sum women_weducR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[23,2]=r(mean)
sum women_weducR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[23,3]=r(mean)
matrix TABLE1[23,4]=TABLE1[23,2]-TABLE1[23,1]
ttest women_weducR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[23,5]=r(p)
ttest women_weducR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[23,6]=TABLE1[23,3]-TABLE1[23,2]
matrix TABLE1[23,7]=r(p)
ttest women_weducR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[23,8]=TABLE1[23,3]-TABLE1[23,1]
matrix TABLE1[23,9]=r(p)

sum edu_men614R1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[24,1]=r(mean)
sum edu_men614R1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[24,2]=r(mean)
sum edu_men614R1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[24,3]=r(mean)
matrix TABLE1[24,4]=TABLE1[24,2]-TABLE1[24,1]
ttest edu_men614R1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[24,5]=r(p)
ttest edu_men614R1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[24,6]=TABLE1[24,3]-TABLE1[24,2]
matrix TABLE1[24,7]=r(p)
ttest edu_men614R1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[24,8]=TABLE1[24,3]-TABLE1[24,1]
matrix TABLE1[24,9]=r(p)

sum rec_juntos if sib==0 & round==0 & twosibling==0
matrix TABLE1[25,1]=r(mean)
sum rec_juntos if sib==0 & round==0 & twosibling==1
matrix TABLE1[25,2]=r(mean)
sum rec_juntos if sib==0 & round==0 & $sample_j1
matrix TABLE1[25,3]=r(mean)
matrix TABLE1[25,4]=TABLE1[25,2]-TABLE1[25,1]
ttest rec_juntos if sib==0 & round==0 , by(twosibling)
matrix TABLE1[25,5]=r(p)
ttest rec_juntos if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[25,6]=TABLE1[25,3]-TABLE1[25,2]
matrix TABLE1[25,7]=r(p)
ttest rec_juntos if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[25,8]=TABLE1[25,3]-TABLE1[25,1]
matrix TABLE1[25,9]=r(p)

sum secondjuntos if sib==0 & round==0 & twosibling==0
matrix TABLE1[26,1]=r(mean)
sum secondjuntos if sib==0 & round==0 & twosibling==1
matrix TABLE1[26,2]=r(mean)
sum secondjuntos if sib==0 & round==0 & $sample_j1
matrix TABLE1[26,3]=r(mean)
matrix TABLE1[26,4]=TABLE1[26,2]-TABLE1[26,1]
ttest secondjuntos if sib==0 & round==0 , by(twosibling)
matrix TABLE1[26,5]=r(p)
ttest secondjuntos if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[26,6]=TABLE1[26,3]-TABLE1[26,2]
matrix TABLE1[26,7]=r(p)
ttest secondjuntos if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[26,8]=TABLE1[26,3]-TABLE1[26,1]
matrix TABLE1[26,9]=r(p)

sum altitudeR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[27,1]=r(mean)
sum altitudeR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[27,2]=r(mean)
sum altitudeR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[27,3]=r(mean)
matrix TABLE1[27,4]=TABLE1[27,2]-TABLE1[27,1]
ttest altitudeR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[27,5]=r(p)
ttest altitudeR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[27,6]=TABLE1[27,3]-TABLE1[27,2]
matrix TABLE1[27,7]=r(p)
ttest altitudeR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[27,8]=TABLE1[27,3]-TABLE1[27,1]
matrix TABLE1[27,9]=r(p)

sum ruralR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[28,1]=r(mean)
sum ruralR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[28,2]=r(mean)
sum ruralR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[28,3]=r(mean)
matrix TABLE1[28,4]=TABLE1[28,2]-TABLE1[28,1]
ttest ruralR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[28,5]=r(p)
ttest ruralR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[28,6]=TABLE1[28,3]-TABLE1[28,2]
matrix TABLE1[28,7]=r(p)
ttest ruralR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[28,8]=TABLE1[28,3]-TABLE1[28,1]
matrix TABLE1[28,9]=r(p)

sum HHSIZER1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[29,1]=r(mean)
sum HHSIZER1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[29,2]=r(mean)
sum HHSIZER1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[29,3]=r(mean)
matrix TABLE1[29,4]=TABLE1[29,2]-TABLE1[29,1]
ttest HHSIZER1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[29,5]=r(p)
ttest HHSIZER1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[29,6]=TABLE1[29,3]-TABLE1[29,2]
matrix TABLE1[29,7]=r(p)
ttest HHSIZER1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[29,8]=TABLE1[29,3]-TABLE1[29,1]
matrix TABLE1[29,9]=r(p)

sum wiR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[30,1]=r(mean)
sum wiR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[30,2]=r(mean)
sum wiR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[30,3]=r(mean)
matrix TABLE1[30,4]=TABLE1[30,2]-TABLE1[30,1]
ttest wiR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[30,5]=r(p)
ttest wiR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[30,6]=TABLE1[30,3]-TABLE1[30,2]
matrix TABLE1[30,7]=r(p)
ttest wiR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[30,8]=TABLE1[30,3]-TABLE1[30,1]
matrix TABLE1[30,9]=r(p)

sum totalexp_rpc  if sib==0 & round==0 & twosibling==0
matrix TABLE1[31,1]=r(mean)
sum totalexp_rpc  if sib==0 & round==0 & twosibling==1
matrix TABLE1[31,2]=r(mean)
sum totalexp_rpc  if sib==0 & round==0 & $sample_j1
matrix TABLE1[31,3]=r(mean)
matrix TABLE1[31,4]=TABLE1[31,2]-TABLE1[31,1]
ttest totalexp_rpc  if sib==0 & round==0 , by(twosibling)
matrix TABLE1[31,5]=r(p)
ttest totalexp_rpc  if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[31,6]=TABLE1[31,3]-TABLE1[31,2]
matrix TABLE1[31,7]=r(p)
ttest totalexp_rpc  if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[31,8]=TABLE1[31,3]-TABLE1[31,1]
matrix TABLE1[31,9]=r(p)

sum CETH if sib==0 & round==0 & twosibling==0
matrix TABLE1[32,1]=r(mean)
sum CETH if sib==0 & round==0 & twosibling==1
matrix TABLE1[32,2]=r(mean)
sum CETH if sib==0 & round==0 & $sample_j1
matrix TABLE1[32,3]=r(mean)
matrix TABLE1[32,4]=TABLE1[32,2]-TABLE1[32,1]
ttest CETH if sib==0 & round==0 , by(twosibling)
matrix TABLE1[32,5]=r(p)
ttest CETH if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[32,6]=TABLE1[32,3]-TABLE1[32,2]
matrix TABLE1[32,7]=r(p)
ttest CETH if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[32,8]=TABLE1[32,3]-TABLE1[32,1]
matrix TABLE1[32,9]=r(p)

sum age_caregiverR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[33,1]=r(mean)
sum age_caregiverR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[33,2]=r(mean)
sum age_caregiverR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[33,3]=r(mean)
matrix TABLE1[33,4]=TABLE1[33,2]-TABLE1[33,1]
ttest age_caregiverR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[33,5]=r(p)
ttest age_caregiverR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[33,6]=TABLE1[33,3]-TABLE1[33,2]
matrix TABLE1[33,7]=r(p)
ttest age_caregiverR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[33,8]=TABLE1[33,3]-TABLE1[33,1]
matrix TABLE1[33,9]=r(p)

sum CAREED if sib==0 & round==0 & twosibling==0
matrix TABLE1[34,1]=r(mean)
sum CAREED if sib==0 & round==0 & twosibling==1
matrix TABLE1[34,2]=r(mean)
sum CAREED if sib==0 & round==0 & $sample_j1
matrix TABLE1[34,3]=r(mean)
matrix TABLE1[34,4]=TABLE1[34,2]-TABLE1[34,1]
ttest CAREED if sib==0 & round==0 , by(twosibling)
matrix TABLE1[34,5]=r(p)
ttest CAREED if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[34,6]=TABLE1[34,3]-TABLE1[34,2]
matrix TABLE1[34,7]=r(p)
ttest CAREED if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[34,8]=TABLE1[34,3]-TABLE1[34,1]
matrix TABLE1[34,9]=r(p)

sum hh_agricR1 if sib==0 & round==0 & twosibling==0
matrix TABLE1[35,1]=r(mean)
sum hh_agricR1 if sib==0 & round==0 & twosibling==1
matrix TABLE1[35,2]=r(mean)
sum hh_agricR1 if sib==0 & round==0 & $sample_j1
matrix TABLE1[35,3]=r(mean)
matrix TABLE1[35,4]=TABLE1[35,2]-TABLE1[35,1]
ttest hh_agricR1 if sib==0 & round==0 , by(twosibling)
matrix TABLE1[35,5]=r(p)
ttest hh_agricR1 if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[35,6]=TABLE1[35,3]-TABLE1[35,2]
matrix TABLE1[35,7]=r(p)
ttest hh_agricR1 if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[35,8]=TABLE1[35,3]-TABLE1[35,1]
matrix TABLE1[35,9]=r(p)

sum pob_mon if sib==0 & round==0 & twosibling==0
matrix TABLE1[37,1]=r(mean)
sum pob_mon if sib==0 & round==0 & twosibling==1
matrix TABLE1[37,2]=r(mean)
sum pob_mon if sib==0 & round==0 & $sample_j1
matrix TABLE1[37,3]=r(mean)
matrix TABLE1[37,4]=TABLE1[37,2]-TABLE1[37,1]
ttest pob_mon if sib==0 & round==0 , by(twosibling)
matrix TABLE1[37,5]=r(p)
ttest pob_mon if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[37,6]=TABLE1[37,3]-TABLE1[37,2]
matrix TABLE1[37,7]=r(p)
ttest pob_mon if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[37,8]=TABLE1[37,3]-TABLE1[37,1]
matrix TABLE1[37,9]=r(p)

sum sev_pob if sib==0 & round==0 & twosibling==0
matrix TABLE1[38,1]=r(mean)
sum sev_pob if sib==0 & round==0 & twosibling==1
matrix TABLE1[38,2]=r(mean)
sum sev_pob if sib==0 & round==0 & $sample_j1
matrix TABLE1[38,3]=r(mean)
matrix TABLE1[38,4]=TABLE1[38,2]-TABLE1[38,1]
ttest sev_pob if sib==0 & round==0 , by(twosibling)
matrix TABLE1[38,5]=r(p)
ttest sev_pob if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[38,6]=TABLE1[38,3]-TABLE1[38,2]
matrix TABLE1[38,7]=r(p)
ttest sev_pob if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[38,8]=TABLE1[38,3]-TABLE1[38,1]
matrix TABLE1[38,9]=r(p)

sum des_cron if sib==0 & round==0 & twosibling==0
matrix TABLE1[39,1]=r(mean)
sum des_cron if sib==0 & round==0 & twosibling==1
matrix TABLE1[39,2]=r(mean)
sum des_cron if sib==0 & round==0 & $sample_j1
matrix TABLE1[39,3]=r(mean)
matrix TABLE1[39,4]=TABLE1[39,2]-TABLE1[39,1]
ttest des_cron if sib==0 & round==0 , by(twosibling)
matrix TABLE1[39,5]=r(p)
ttest des_cron if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[39,6]=TABLE1[39,3]-TABLE1[39,2]
matrix TABLE1[39,7]=r(p)
ttest des_cron if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[39,8]=TABLE1[39,3]-TABLE1[39,1]
matrix TABLE1[39,9]=r(p)

sum prom_nbi if sib==0 & round==0 & twosibling==0
matrix TABLE1[40,1]=r(mean)
sum prom_nbi if sib==0 & round==0 & twosibling==1
matrix TABLE1[40,2]=r(mean)
sum prom_nbi if sib==0 & round==0 & $sample_j1
matrix TABLE1[40,3]=r(mean)
matrix TABLE1[40,4]=TABLE1[40,2]-TABLE1[40,1]
ttest prom_nbi if sib==0 & round==0 , by(twosibling)
matrix TABLE1[40,5]=r(p)
ttest prom_nbi if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[40,6]=TABLE1[40,3]-TABLE1[40,2]
matrix TABLE1[40,7]=r(p)
ttest prom_nbi if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[40,8]=TABLE1[40,3]-TABLE1[40,1]
matrix TABLE1[40,9]=r(p)

sum porc_cp if sib==0 & round==0 & twosibling==0
matrix TABLE1[41,1]=r(mean)
sum porc_cp if sib==0 & round==0 & twosibling==1
matrix TABLE1[41,2]=r(mean)
sum porc_cp if sib==0 & round==0 & $sample_j1
matrix TABLE1[41,3]=r(mean)
matrix TABLE1[41,4]=TABLE1[41,2]-TABLE1[41,1]
ttest porc_cp if sib==0 & round==0 , by(twosibling)
matrix TABLE1[41,5]=r(p)
ttest porc_cp if sib==0 & round==0 , by(q1q2twosib)
matrix TABLE1[41,6]=TABLE1[41,3]-TABLE1[41,2]
matrix TABLE1[41,7]=r(p)
ttest porc_cp if sib==0 & round==0 , by(q1q2vsrest)
matrix TABLE1[41,8]=TABLE1[41,3]-TABLE1[41,1]
matrix TABLE1[41,9]=r(p)

xml_tab TABLE1, save("`rutaf'\tableA1_appendixA.xls") replace format(SCLR3 NCLR2) sheet(tableA1)
